library lib_core;

import 'package:lib_core/gt_message_center.dart';
import 'package:lib_core/lib_core_event_channel.dart';
import 'package:lib_core/lib_core_method_channel.dart';
import 'package:lib_core/logger/gt_logger.dart';
import 'package:lib_core/model/gt_global_config.dart';
import 'package:lib_core/model/gt_global_config_event_action.dart';
import 'package:lib_core/provider/gt_global_config_change_notifier.dart';

export 'package:lib_core/gt_app_config_api.dart';
export "package:lib_core/gt_message_center.dart";
export "package:lib_core/lib_core_method_channel.dart";
export 'package:lib_core/lib_core_event_channel.dart';
export 'package:lib_core/model/route_args.dart';
export 'package:lib_core/model/gt_global_config.dart';
export 'package:lib_core/model/lib_core_event_model.dart';
export 'package:lib_core/model/gt_global_config_event_action.dart';
export 'package:lib_core/provider/gt_navigator_provider.dart';
export 'package:lib_core/provider/gt_global_config_change_notifier.dart';
export 'package:lib_core/logger/gt_logger.dart';
export 'package:lib_core/logger/gt_logger_level.dart';
export 'package:lib_core/extension/list_extension.dart';
export 'package:lib_core/extension/string_to_num_extension.dart';
export 'package:lib_core/utils/gt_number_format.dart';
export 'package:lib_core/utils/gt_number_format2.dart';
export 'package:lib_core/utils/gt_number_format_v3.dart';
export 'package:lib_core/model/gt_env_type.dart';

export 'package:collection/collection.dart';

class GTLibCore {

  static final GTLibCore _instance = GTLibCore._();

  GTLibCore._();

  static GTLibCore get instance => _instance;

  static GTGlobalConfig get globalConfig => GTGlobalConfigChangeNotifier.globalConfig;

  /// 初始化配置参数
  static void setGlobalConfig(GTGlobalConfig globalConfig) {
    GTGlobalConfigChangeNotifier.setupGlobalConfig(globalConfig);
  }

  /// 相关初始化
  static void setup(GTGlobalConfig globalConfig) {
    // 初始化参数，并开始 监听变更
    GTGlobalConfigChangeNotifier.setupGlobalConfig(globalConfig);
    GTGlobalConfigChangeNotifier.instance;
    GTLibCoreMethodChannel.instance;
    GTMessageCenter.instance;

    // 日志库初始化
    GTLogger.setup();
  }

  /// 开始监听
  static void startListen() {
    // LibCore EventChannel 开始监听原生侧消息
    GTLibCoreEventChannel.startListen();
  }

  /// 监听 GlobalConfig 状态变更
  static void addChangeListener(GTGlobalConfigEventAction action, GTGlobalConfigChangeListener listener) {
    GTGlobalConfigChangeNotifier.addChangeListener(action, listener);
  }

  static void removeChangeListener(GTGlobalConfigEventAction action, GTGlobalConfigChangeListener listener) {
    GTGlobalConfigChangeNotifier.removeChangeListener(action, listener);
  }

  static void addAllChangeListener(GTGlobalConfigChangeListener listener) {
    GTGlobalConfigChangeNotifier.addChangeListenerByList(GTGlobalConfigEventAction.values, listener);
  }

  static void removeAllChangeListener(GTGlobalConfigChangeListener listener) {
    GTGlobalConfigChangeNotifier.addChangeListenerByList(GTGlobalConfigEventAction.values, listener);
  }

}
